//
//  Test.m
//  数组
//
//  Created by qianfeng on 15/8/16.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "Test.h"

@implementation Test

+(void)printfDogInfo{
    Dog * dog1 = [[Dog alloc]initWithName:@"jk1" andAge:1];
    Dog * dog2 = [[Dog alloc]initWithName:@"jk2" andAge:2];
    Dog * dog3 = [[Dog alloc]initWithName:@"jk3" andAge:3];
    Dog * dog4 = [[Dog alloc]initWithName:@"jk4" andAge:4];
    Dog * dog5 = [[Dog alloc]initWithName:@"jk5" andAge:5];
    
    NSArray * dogs = @[dog1,dog2,dog3,dog4,dog5];
    for (Dog * dog in dogs) {
        [dog printInfo];
    }

}

+(void)DogAndCat{
    Dog * dog1 = [[Dog alloc]initWithName:@"jk1" andAge:1];
    Dog * dog2 = [[Dog alloc]initWithName:@"jk2" andAge:2];
    Dog * dog3 = [[Dog alloc]initWithName:@"jk3" andAge:3];
    
    Cat * cat1 = [[Cat alloc] init];
    Cat * cat2 = [[Cat alloc] init];
    Cat * cat3 = [[Cat alloc] init];
    NSArray * objects = @[dog1,cat1,cat2,cat3,dog2,dog3];
    for (id object in objects) {
        if ([object isKindOfClass:[Dog class]]) {
            [object bark];
        }
        if ([object isKindOfClass:[Cat class]]) {
            [object wash];
        }
    }
    
}

+(void)theCountOfWords:(NSString *)str{
//    NSMutableString * strstr = [NSMutableString stringWithString:str];
    
    NSMutableArray * array =(NSMutableArray *)[str componentsSeparatedByString:@" "];
    for (int i = 0; i < array.count; i++) {
        if ([[array objectAtIndex:i] length] == 0) {
            [array removeObjectAtIndex:i];
            i--;
        }
    }
    NSLog(@"%lu",array.count);
}


+(void)niXuOfWord:(NSString *)str{
    NSMutableArray * array = (NSMutableArray *)[str componentsSeparatedByString:@" "];

    NSMutableString * strstr = [[NSMutableString alloc] init];
    for ( int i = 0 ; i < array.count; i++) {
        if ([[array objectAtIndex:i] length] == 0) {
            [array removeObjectAtIndex:i];
            i--;
        }
    }
    for (int i = 0; i < array.count; i++) {
        [strstr insertString:[NSString stringWithFormat:@"%@%c",[array objectAtIndex:i],' '] atIndex:0];
    }
    NSLog(@"%@",strstr);
 
}

 
+ (void)pinJieStr1:(NSString *)str1 andStr2:(NSString *)str2{
    NSMutableArray * array1 = (NSMutableArray *)[str1 componentsSeparatedByString:@" "];
    NSMutableArray * array2 = (NSMutableArray *)[str2 componentsSeparatedByString:@" "];
    for (int i = 0; i < array1.count; i++) {
        if ([[array1 objectAtIndex:i] length] == 0) {
            [array1 removeObjectAtIndex:i];
            i--;
        }
    }
    for (int i = 0; i < array2.count; i++) {
        if ([[array2 objectAtIndex:i] length] == 0) {
            [array2 removeObjectAtIndex:i];
            i--;
        }
    }
    NSMutableString * str = [[NSMutableString alloc]init];

    for (int i = 0; i < (array1.count>array2.count?array1.count:array2.count); i++) {
        if (i >= (array1.count>array2.count?array2.count:array1.count)) {
            [str appendFormat:@"%@ ",[array1.count>array2.count?array1:array2 objectAtIndex:i]];
            continue;
        }
       NSMutableString * str11 = [array1 objectAtIndex:i];
       NSMutableString * str22 = [array2 objectAtIndex:i];
        [str appendFormat:@"%@ %@ ",str11,str22];
      
    }
     NSLog(@"%@",str);
}



@end
